package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: itheima
 * @create: 2021-12-20 12:05
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class ChannelController {


    @Autowired
    private IWmChannelService wmChannelService;

    /**
     * 根据名称模糊查询分页列表
     *
     * @param dto 包含频道名称，分页信息
     * @return 频道分页列表
     */
    @PostMapping("/list")
    @ApiImplicitParam(name = "dto", value = "查询对象", required = true, dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {
        //int i = 1 / 0;
        return wmChannelService.listByName(dto);
    }

    /**
     * 保存频道
     *
     * @param entity
     * @return
     */
    @PostMapping
    public ResponseResult saveChannel(@RequestBody WmChannel entity) {
        return wmChannelService.saveChannel(entity);
    }


    /**
     * 查询所有的频道
     *
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }

    /**
     * 修改频道
     * PUT 请求
     */
    @PutMapping
    public ResponseResult updateChannel(@RequestBody WmChannel channel) {
        return wmChannelService.updateChannel(channel);

     * @param channel
     * @return
     */
    @PutMapping
    public ResponseResult updateChannels(@RequestBody WmChannel channel) {
        wmChannelService.updateChannels(channel);
        return ResponseResult.okResult();
    }

    /**
     * 删除频道
     * delete  请求  {id}
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteChannel(@PathVariable("id") Integer channelId) {
        return wmChannelService.deleteChannelById(channelId);
    }

     */
    @DeleteMapping("{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id) {
        wmChannelService.deleteChannel(id);
        return ResponseResult.okResult();
    }
}
